package com.pft.web.view.dialog;

import android.app.Activity;
import android.text.TextUtils;
import android.view.View;
import android.widget.TextView;

import com.pft.web.R;

import butterknife.BindView;
import butterknife.ButterKnife;

public class ConfirmDialog extends BaseDialog {

    @BindView(R.id.dialog_title)
    TextView titleTxv;

    @BindView(R.id.dialog_content)
    TextView contentTxv;

    @BindView(R.id.dialog_cancel)
    TextView cancelTxv;

    @BindView(R.id.dialog_confirm)
    TextView confirmTxv;

    public ConfirmDialog(Activity activity) {
        super(activity);
    }

    @Override
    protected void initView() {
        setContentView(R.layout.dialog_confirm);
        ButterKnife.bind(this);

        setCancelable(true);
        setCanceledOnTouchOutside(true);
    }

    public void setTitleText(String text) {
        if (!TextUtils.isEmpty(text)) {
            titleTxv.setText(text);
        }
    }

    public void setContentText(CharSequence text) {
        if (!TextUtils.isEmpty(text)) {
            contentTxv.setText(text);
        }
    }

    public void setCancelText(String text) {
        if (!TextUtils.isEmpty(text)) {
            cancelTxv.setText(text);
        }
    }

    public void setConfirmText(String text) {
        if (!TextUtils.isEmpty(text)) {
            confirmTxv.setText(text);
        }
    }

    public void setButtonClickListener(final OnButtonClickListener listener) {
        confirmTxv.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                try {
                    dismiss();
                } catch (Throwable e) {
                    e.printStackTrace();
                }
                if (listener != null) {
                    listener.onConfirm();
                }
            }
        });

        cancelTxv.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                try {
                    dismiss();
                } catch (Throwable e) {
                    e.printStackTrace();
                }
                if (listener != null) {
                    listener.onCancel();
                }
            }
        });
    }

    public interface OnButtonClickListener {

        void onConfirm();

        void onCancel();

    }
}
